package com.spring.basetype.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.spring.basetype.web.model.BaseType;
import com.spring.basetype.web.model.BaseTypeCode;
import com.spring.basetype.web.service.BaseTypeService;
import com.spring.security.web.model.BaseResult;
import com.sso.api.web.dao.SsoMapper;

/**
 * 定制开发
 * @author wojunyu
 *
 */
@Controller
@RequestMapping(value = "/baseType")
public class BaseTypeController {
	@Resource
	private BaseTypeService baseTypeService;
	@Resource
	private SsoMapper ssoMapper;
	
	/**
	 * 公共展现界面
	 * @param querydate
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/index")
    public ModelAndView baseType(HttpServletRequest request){
		return new ModelAndView("main/basetype/basetype");
    }
	

	
	@RequestMapping(value = "/getBaseTypeList")
	@ResponseBody
	public Object getBaseTypeList(String page,String rows,HttpServletRequest request){
	    Map<String, Object> parm = new HashMap<String, Object>();
	    Map<String, Object> retD = new HashMap<String, Object>();
	    
    	PageHelper.startPage(Integer.parseInt(page), Integer.parseInt(rows));
        List<Map<String,Object>> list = baseTypeService.getBaseTypeList(parm);
        PageInfo pageObj = new PageInfo(list);
        retD.put("total", pageObj.getTotal());
        retD.put("rows", list); 	
	    return retD;
	}


	@RequestMapping(value = "/saveOrUpdateBaseType")
    @ResponseBody
    public Object saveOrUpdateBaseType(BaseType bt,HttpServletRequest request){
        BaseResult br=null;		
    	try{    		
			br=baseTypeService.saveOrUpdateBaseType(bt);  		
    	}catch(Exception e){
    		br=new BaseResult("0","系统异常");
    		e.printStackTrace();
    	}
        	return br;
    }

	@RequestMapping(value = "/deleteBaseType")
    @ResponseBody
    public Object deleteBaseType(String type,HttpServletRequest request){
        BaseResult br=null;		
    	try{    		
			br=baseTypeService.deleteBaseType(type);		
    	}catch(Exception e){
    		br=new BaseResult("0","系统异常");
    		e.printStackTrace();
    	}
        	return br;
    }
	
	@RequestMapping(value = "/getBaseTypeCodeList")
    @ResponseBody
    public Object getBaseTypeCodeList(String page,String rows,String type,HttpServletRequest request) throws Exception{
	    Map<String, Object> parm = new HashMap<String, Object>();
	    Map<String, Object> retD = new HashMap<String, Object>();
	    
    	PageHelper.startPage(Integer.parseInt(page), Integer.parseInt(rows));
    	List<BaseTypeCode> list = baseTypeService.getBaseTypeCodeList(type);
        PageInfo pageObj = new PageInfo(list);
        retD.put("total", pageObj.getTotal());
        retD.put("rows", list); 	
	    return retD;
    }

	@RequestMapping(value = "/saveOrUpdateBaseTypeCode")
    @ResponseBody
    public Object saveOrUpdateBaseTypeCode(BaseTypeCode btc,HttpServletRequest request){
        BaseResult br=null;		
    	try{    		
			br=baseTypeService.saveOrUpdateBaseTypeCode(btc);  		
    	}catch(Exception e){
    		br=new BaseResult("0","系统异常");
    		e.printStackTrace();
    	}
        	return br;
    }
	
	@RequestMapping(value = "/deleteCodeByID")
    @ResponseBody
    public Object deleteCodeByID(String id,HttpServletRequest request){
        BaseResult br=null;		
    	try{    		
			br=baseTypeService.deleteCodeByID(id);	
    	}catch(Exception e){
    		br=new BaseResult("0","系统异常");
    		e.printStackTrace();
    	}
        	return br;
    }

}
